﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web.Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <%--Ext引用--%>
    <script src="Ext/adapter/ext/ext-base.js" type="text/javascript"></script>
    <script src="Ext/ext-all-debug.js" type="text/javascript"></script>
    <link href="Ext/resources/css/ext-all.css" rel="stylesheet" type="text/css" />

     <script type="text/javascript">
         Ext.BLANK_IMAGE_URL = "Ext/resources/images/default/tree/s.gif";
         var tabs = new Ext.TabPanel({
             margins: '5 5 5 0',
             region: 'center',
             layoutOnTabChange: true,
             enableTabScroll: true,
             defaults: {
                 closable: true,
                 loadMask: {
                     msg: '正在加载页面,请稍后...'
                 },
                 autoShow: true
             },
             activeTab: 0,
             items: {
                 title: '我的工作台',
                 autoLoad: {},
                 closable: false,
                 autoLoad: { url: 'YNTravelGrid.aspx', scripts: true },
                 autoScroll: true,
                 iconCls: 'tubiao'
             }
         })

         //增加tabs
         function addTab(tabTitle, tabHtml, tabId, cls, mask) {
             if (mask) {
                 tabs.add({
                     title: tabTitle,
                     iconCls: cls,
                     html: '<iframe src="' + tabHtml + '?width=' + tabs.getInnerWidth() + '&height=' + tabs.getInnerHeight() + '" frameborder=no height=100% width=100% noresize></iframe>',
                     autoDestroy: true,
                     id: tabId
                 }).show();
             }
             else {
                 tabs.add({
                     title: tabTitle,
                     iconCls: cls,
                     autoLoad: { url: tabHtml, scripts: true },
                     autoDestroy: true,
                     autoScroll: true,
                     id: tabId
                 }).show();
             }
         };

         //更新tabs
         function updateTab(tabTitle, tabHtml, tabId, cls, mask) {
             var tab = tabs.getItem(tabId);

             if (tab) {
                 //TODO:更新tab
                 tab.setTitle(tabTitle);
             }
             else {
                 tab = addTab(tabTitle, tabHtml, tabId, cls, mask);
             }
             tabs.setActiveTab(tab);
         };

         Ext.onReady(function () {
             Ext.BLANK_IMAGE_URL = "Ext/resources/images/default/tree/s.gif";
             Ext.QuickTips.init();
             Ext.apply(Ext.QuickTips.getQuickTip(), {
                 maxWidth: 200,
                 minWidth: 100,
                 showDelay: 50,
                 trackMouse: true
             });

             //Default页面布局
             var border = new Ext.Viewport({
                 title: 'Border Layout',
                 layout: 'border',
                 items: [{
                     collapsible: false,
                     region: 'north',
                     contentEl: 'north',
                     border: false,
                     height: 75
                 }, {
                     title: '主菜单',
                     id: 'maintree',
                     region: 'west',
                     frame: true,
                     contentEl: 'west',
                     margins: '5 0 5 5',
                     collapsible: true,
                     split: true,
                     width: 190,
                     minSize: 100,
                     maxSize: 300
                 }, tabs]
             })

             //菜单树
             var createXMLTree = function (el, url, callback) {
                 var tree = new Ext.tree.TreePanel({
                     el: el,
                     border: false,
                     autoScroll: true,
                     animate: true,
                     collapsed: false
                 });
                 var p = new Ext.data.HttpProxy({ method: 'get', url: url });
                 p.on("loadexception", function (t, o, response, e) {
                     if (e) throw e;
                     Ext.Msg.alert('错误信息', 'xml数据读取错误！' + e.text);
                 });
                 var reader = new Ext.data.XmlReader({ meta: { root: 0} });
                 reader.read = function (response) {
                     var doc = response.responseXML;
                     var root = nodeFromXML(doc.documentElement || doc);
                     tree.setRootNode(root);
                     tree.render();
                     Ext.tree.Loaded = true;
                     return true;
                 }
                 p.doRequest('read', null, [''], reader, callback || tree.expand, tree);
                 return tree;
             }

             var nodeFromXML = function (el) {
                 //                if (el.tagName != 'node') return;
                 //                var noPermission = true;
                 //                if (el.attributes[1]) {
                 //                    var roles = el.attributes[1].nodeValue;
                 //                    var roleArry = roles.split(',');
                 //                    for (var i = 0; i < roleArry.length; i++) {
                 //                        if (roleArry[i] != "" && userRoleListStr.indexOf(roleArry[i]) != -1) {
                 //                            noPermission = false;
                 //                        }
                 //                    }
                 //                } else if (el.attributes[0].nodeValue == "root") {
                 //                    noPermission = false;
                 //                }
                 //                if (noPermission) {
                 //                    return;
                 //                }
                 //                var node = new Ext.tree.TreeNode({
                 //                    id: el.attributes[0].nodeValue
                 //                });
                 if (el.tagName != 'node') return;
                 var node = new Ext.tree.TreeNode({
                     id: el.attributes[0].nodeValue
                 });

                 Ext.each(el.childNodes, function (elt) {
                     if (elt.nodeType != 1) return;
                     if (!elt.firstChild) return;
                     switch (elt.nodeName) {
                         case 'text':
                             node.setText(elt.firstChild.nodeValue);
                             break;
                         case 'url':
                             node.attributes.url = elt.firstChild.nodeValue;
                             break;
                         case 'module':
                             node.attributes.module = elt.firstChild.nodeValue;
                             break;
                         case 'iconCls':
                             node.attributes.iconCls = elt.firstChild.nodeValue;
                         case 'width':
                             node.attributes.width = elt.firstChild.nodeValue;
                             break;
                         case 'height':
                             node.attributes.height = elt.firstChild.nodeValue;
                             break;
                         case 'expanded':
                             if (elt.firstChild.nodeValue == 'true') {
                                 node.expanded = true;
                             }
                             break;
                         case 'children':
                             Ext.each(elt.childNodes, function (elem) {
                                 if (elem.nodeType != 1) return;
                                 n = nodeFromXML(elem);
                                 if (n) {
                                     node.appendChild(n);
                                 }
                             });
                             break;
                     }
                 });
                 return node;
             }
             var tree;
             //设置权限           tree = createXMLTree('tree', 'Service/PermissionsService.aspx?Action=LoadPermissionsTree', null);
             tree = createXMLTree('tree', 'Data/NavTree.xml', null);

             var win = new Ext.Window({
                 width: 350,
                 iconCls: 'new_tab',
                 height: 400,
                 closeAction: 'hide',
                 modal: true,
                 plain: true
             });
             //单击菜单节点
             tree.on("click", function (node, event) {
                 if (node.attributes.module == null) {
                     node.attributes.module = 'tabs';
                 }
                 if (node.attributes.module == 'window') {
                     win.title = node.text;
                     if (node.attributes.width != null) {
                         win.width = eval(node.attributes.width);
                     }
                     if (node.attributes.height != null) {
                         win.height = eval(node.attributes.height);
                     }
                     win.autoLoad = {
                         url: "'" + node.attributes.url + "'",
                         scripts: true
                     };

                     win.show(this);
                 } else if (node.attributes.module == 'iframe') {
                     if (node.attributes.url != null && node.attributes.url != '') {
                         Ext.getCmp("maintree").collapse(true);
                         updateTab(node.text, node.attributes.url, 'tabs_' + node.id, node.attributes.iconCls, true);
                     }

                 } else {
                     if (node.attributes.url != null && node.attributes.url != '') {
                         updateTab(node.text, node.attributes.url, 'tabs_' + node.id, node.attributes.iconCls);
                     }
                 }
             }
	    );
         })
    </script>
</head>

<body>
     <div>
        <div id="north" class="x-layout-inactive-content" style="width:100%; height:80px;background-image:url(Images/header_bg.jpg)">
        
    <div style="filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src='Images/Xinye.png', sizingMethod='scale');background-repeat:no-repeat;height:70px;width:250px; position:absolute;top:5px;left:20px" ></div>
          <div  style="position:absolute; font-size:12px; color:Black; top:19px; right:19px">
            登录人：
            <asp:Label ID ="loguser" runat="server" />
<%--            |--%>
<%--            <a id="updatapassword"  style="text-decoration:none;font-size:12px;color:Black;cursor:pointer" onclick="AddPsFormClick()">修改密码</a>
             |
            <A ID="logout" style="text-decoration:none;font-size:12px;color:Black;cursor:pointer" href="Login.aspx" >注销</A>--%>
        </div>      
       
        </div>
       
        <!-- West Region -->
        <div id="west" class="x-layout-inactive-content">
            <div id="tree" style="width: 200px; height: 500px;">
            </div>
        </div>
        <!-- Center Region -->
        <div id="center" class="x-layout-inactive-content">
            <!-- Product Grid -->
            <div id="product-grid-panel">
                <div id="product-grid" style="height: 500px;">
                </div>
            </div>
        </div>
        <!-- Product Details Dialog -->
        <div id="product-edit-dialog" style="visibility: hidden;">
            <div class="x-dlg-hd">
                Product Details</div>
            <div class="x-dlg-bd">
                <div id="product-edit-layout" class="x-layout-inactive-content">
                    <div id="product-edit-form">
                    </div>
                </div>
            </div>
        </div>
        <!-- Product Categories Dialog -->
        <div id="category-dialog" style="visibility: hidden;">
            <div class="x-dlg-hd">
                Product Categories</div>
            <div class="x-dlg-bd">
                <div id="category-center" class="x-layout-inactive-content" style="padding: 10px;">
                    <!-- Category Grid -->
                    <div id="category-grid-panel">
                        <div id="category-grid">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Category Details Dialog -->
        <div id="category-edit-dialog" style="visibility: hidden;">
            <div class="x-dlg-hd">
                Category Details</div>
            <div class="x-dlg-bd">
                <div id="category-edit-layout" class="x-layout-inactive-content">
                    <div id="category-edit-form">
                    </div>
                </div>
            </div>
        </div>
        <!-- Product Suppliers Dialog -->
        <div id="supplier-dialog" style="visibility: hidden;">
            <div class="x-dlg-hd">
                Product Suppliers</div>
            <div class="x-dlg-bd">
                <div id="supplier-center" class="x-layout-inactive-content" style="padding: 10px;">
                    <!-- Supplier Grid -->
                    <div id="supplier-grid-panel">
                        <div id="supplier-grid">
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <!-- Supplier Details Dialog -->
        <div id="supplier-edit-dialog" style="visibility: hidden;">
            <div class="x-dlg-hd">
                Supplier Details</div>
            <div class="x-dlg-bd">
                <div id="supplier-edit-layout" class="x-layout-inactive-content">
                    <div id="supplier-edit-form">
                    </div>
                </div>
            </div>
        </div>   
</body>
</html>
